﻿// Lee dialog 1.0 http://www.xij.cn/blog/?p=68

var dialogFirst=true;

function dialog(title,content,width,height,cssName,okFunc,vTop){
	if(dialogFirst==true){
		var temp_float=new String;
		temp_float="<div id=\"floatBoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;\"></div>";
		temp_float+="<div id=\"floatBox\" class=\"floatBox\">";
		temp_float+="<div class=\"floattitle\"><h4></h4><span><input type=\"button\" value=\"\" class=\"closebutton\"/></span></div>";
		temp_float+="<div class=\"floatcontent\"></div>";
		//temp_float+="<div class=\"floatboxbtm\"><span><input type=\"button\" value=\"确认\" class=\"buttonok\"/>&nbsp;&nbsp;<input type=\"button\" value=\"取消\" class=\"buttoncan\"/></span></div>";
		temp_float+="</div>";
		$("body").append(temp_float);
		dialogFirst=false;
	}
	$("#floatBox .floattitle span").click(function(){
		hideMe();
	});
	
	$("#floatBox .floattitle h4").html(title);
	contentType=content.substring(0,content.indexOf(":"));
	content=content.substring(content.indexOf(":")+1,content.length);
	switch(contentType){
		case "url":
			var content_array=content.split("?");
			$("#floatBox .floatcontent").ajaxStart(function(){
				$(this).html("loading...");
			});
			$.ajax({
				type:content_array[0],
			    url:content_array[1],
			    data:content_array[2],
				error:function(){
					$("#floatBox .floatcontent").html("error...");
				},
			    success:function(html){
					$("#floatBox .floatcontent").html(html);
			    }
			});
			break;
		case "text":
			$("#floatBox .floatcontent").html(content);
			break;
		case "id":
			$("#floatBox .floatcontent").html($("#"+content+"").html());
			break;
		case "iframe":
			$("#floatBox .floatcontent").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+(parseInt(height)-30)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
	}
	$("#floatBoxBg").show();
	$("#floatBoxBg").animate({opacity:"0.2"},"normal");
	$("#floatBox").show();
	$("#floatBox").attr("class","floatBox "+cssName);
	$("#floatBox").css({left:(($(document).width())/2-(parseInt(width)/2))+"px",top:($(document).scrollTop()+150)+"px",width:width,height:height});
	if(vTop == undefined){
		vTop = 150;
	}
	$("#floatBox").animate({top:($(document).scrollTop()+vTop)+"px"},"normal"); 
}

function msgDialog(title,content,width,height,cssName,okFunc){
	if(dialogFirst==true){
		var temp_float=new String;
		temp_float="<div id=\"floatBoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;\"></div>";
		temp_float+="<div id=\"floatBox\" class=\"floatBox\">";
		temp_float+="<div class=\"floattitle\"><h4></h4><span><input type=\"button\" value=\"\" class=\"closebutton\"/></span></div>";
		temp_float+="<div class=\"floatcontent\"></div>";
		//temp_float+="<div class=\"floatboxbtm\"><span><input type=\"button\" value=\"确认\" class=\"buttonok\"/>&nbsp;&nbsp;<input type=\"button\" value=\"取消\" class=\"buttoncan\"/></span></div>";
		temp_float+="</div>";
		$("body").append(temp_float);
		dialogFirst=false;
	}
	$("#floatBox .floattitle span").click(function(){
		msgHideMe();
	});
	
	$("#floatBox .floattitle h4").html(title);
	contentType=content.substring(0,content.indexOf(":"));
	content=content.substring(content.indexOf(":")+1,content.length);
	switch(contentType){
		case "url":
			var content_array=content.split("?");
			$("#floatBox .floatcontent").ajaxStart(function(){
				$(this).html("loading...");
			});
			$.ajax({
				type:content_array[0],
			    url:content_array[1],
			    data:content_array[2],
				error:function(){
					$("#floatBox .floatcontent").html("error...");
				},
			    success:function(html){
					$("#floatBox .floatcontent").html(html);
			    }
			});
			break;
		case "text":
			$("#floatBox .floatcontent").html(content);
			break;
		case "id":
			$("#floatBox .floatcontent").html($("#"+content+"").html());
			break;
		case "iframe":
			$("#floatBox .floatcontent").html("<iframe src=\""+content+"\" width=\"98%\" height=\""+(parseInt(height)-30)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
	}
	$("#floatBoxBg").show();
	$("#floatBoxBg").animate({opacity:"0.2"},"normal");
	$("#floatBox").show();
	$("#floatBox").attr("class","floatBox "+cssName);
	$("#floatBox").css({left:(($(document).width())/2-(parseInt(width)/2))+"px",top:($(document).scrollTop()+250)+"px",width:width,height:height});
	$("#floatBox").animate({top:($(document).scrollTop()+250)+"px"},"normal"); 
}

function hideMe(){
	$("#floatBoxBg").animate({opacity:"0"},"fast",function(){$(this).hide();});
	$("#floatBox").animate({top:(($(document).scrollTop()+150))+"px"},"fast",function(){$(this).hide();});
//	document.body.removeChild(document.getElementById("floatBoxBg"));
}

function msgHideMe(){
	$("#floatBoxBg").animate({opacity:"0"},"fast",function(){$(this).hide();});
	$("#floatBox").animate({top:(($(document).scrollTop()+250))+"px"},"fast",function(){$(this).hide();});
//	document.body.removeChild(document.getElementById("floatBoxBg"));
}

function doHelp(url,title){
	window.open(url,title,'left=0,top=0,width='+ (screen.availWidth - 10) +',height='+ (screen.availHeight-50) +',scrollbars=yes,location=yes,menubar=yes,resizable=yes,toolbar=yes');
}